package handler

import (
	"context"
	"rpc/global"
	"rpc/model"
	__ "rpc/proto"
)

type Server struct {
	__.UnimplementedUserServer
}

// SayHello implements helloworld.GreeterServer
func (s *Server) Login(_ context.Context, in *__.LoginRequest) (*__.LoginResponse, error) {
	user := model.Users{}
	global.DB.Find(&user)
	return &__.LoginResponse{
		Id: user.Id,
	}, nil
}
func (s *Server) AddVideo(_ context.Context, in *__.AddVideoRequest) (*__.AddVideoResponse, error) {
	video := model.Videos{}
	global.DB.Create(&video)
	return &__.AddVideoResponse{
		Id: int64(video.Id),
	}, nil
}

//	func (s *Server) ListVideo(_ context.Context, in *__.ListVideoRequest) (*__.ListVideoResponse, error) {
//		video := model.Videos{}
//		global.DB.Find(&video)
//		videos := []model.Videos{}
//		for _, i2 := range videos {
//			list := model.Videos{
//				UserId: i2.UserId,
//				Name:   i2.Name,
//				Like:   i2.Like,
//				People: i2.People,
//				Gift:   i2.Gift,
//				Img:    i2.Img,
//				Id:     i2.Id,
//			}
//			video = append(videos, list)
//
//		}
//		return &__.ListVideoResponse{
//			List: video,
//		}, nil
//	}
func (s *Server) InfoVideo(_ context.Context, in *__.InfoVideoRequest) (*__.InfoVideoResponse, error) {
	video := model.Videos{}
	global.DB.Find(&video)
	return &__.InfoVideoResponse{
		UserId: video.UserId,
		Name:   video.Name,
		Like:   video.Like,
		People: video.People,
		Gift:   video.Gift,
		Img:    video.Img,
	}, nil
}
func (s *Server) Video(_ context.Context, in *__.VideoRequest) (*__.VideoResponse, error) {

	return &__.VideoResponse{}, nil
}
